using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using MIS.EN.WebDav;

namespace MIS.EN.Exchange.Parsers
{
    internal class DateTimeWebDavResultValueParser : IWebDavResultValueParser
    {
        #region IWebDavResultValueParser Members

        public object ParseValue(XmlNode responseNode, WebDavXmlHelper webDavXmlHelper, 
            string namespacePrefix, string propertyName, string type)
        {
            return webDavXmlHelper.GetDateTimePropertyValueFromResponseNode(responseNode, namespacePrefix, propertyName);
        }

        public string GetFormattedValue(object propertyValue)
        {
            string formattedDate = string.Empty;
            if (propertyValue != null)
            {
                formattedDate = ((DateTime)propertyValue).ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
            }
            return formattedDate;
        }

        public string GetFormattedValueForSearch(object propertyValue)
        {
            return "CAST(\"" + this.GetFormattedValue(propertyValue) + "\" AS 'dateTime')";
        }

        #endregion
    }
}